﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MedicalLog.WebUI.Models.PatientViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Registrar Paciente
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeaderContent" runat="server">
    <link href="../../Content/JQueryUI/start/jquery-ui-1.8.9.custom.css" rel="stylesheet"
        type="text/css" />
    <link href="../../Content/jquery-ui-timepicker.css" rel="stylesheet" type="text/css" />
    <script src="../../Scripts/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Scripts/MicrosoftMvcValidation.js" type="text/javascript"></script>
    <script type="text/javascript">

        $(document).ready(function () {
            $('.footer').hide();
            $('.footer').fadeIn('5000');
            $('#TutorContainer').hide();


            $('#DateofBirth').datepicker({
                dateFormat: "dd/mm/yy",
                yearRange: "-90:+0",
                changeMonth: true,
                changeYear: true,
                showon: "both",
                buttonimage: "../../content/images/calendar.gif",
                buttonimageonly: true
            });

            $('#Telephone').mask("(999) 999-9999");
            $('#Celphone').mask("(999) 999-9999");
            $('#IdentificationNumber').mask("999-9999999-9");
            $('#TutorTelefono').mask("(999) 999-9999");
            $('#TutorCelular').mask("(999) 999-9999");
            $('#TutorCedula').mask("999-9999999-9");

            $('#DateofBirth').change(function () {
                var today = new Date();
                var mydateStr = $(this).val();
                var mydate = new Date(mydateStr.substr(6, 4), mydateStr.substr(3, 2) - 1, mydateStr.substr(0, 2));

                if ((today.getFullYear() - mydate.getFullYear()) < 18) {
                    $('#TutorContainer').show('slow');

                }
                else if ((today.getFullYear() - mydate.getFullYear()) == 18) {

                    if (mydate.getMonth() > today.getMonth()) {

                        $('#TutorContainer').show('slow');

                    }

                    else if (mydate.getMonth() == today.getMonth())
                        if (mydate.getDate() > today.getDate()) {

                            $('#TutorContainer').show('slow');
                        }
                        else {
                            $('#TutorContainer').hide('slow');
                            $('#pageFoot').show('slow');
                        }
                    else {
                        $('#TutorContainer').hide('slow');
                        $('#pageFoot').show('slow');
                    }
                }

                else {
                    $('#TutorContainer').hide('slow');
                    $('#pageFoot').show('slow');
                }

                if ($('#TutorContainer').is(':visible')) {
                    $('#pageFoot').hide();
                }
                else {
                    $('#pageFoot').show();
                }

            });

            $(function () {
                $('#Tutor_Name').focusout(function () {
                    var Text = $('#Tutor_Name').val();
                    Text = Text.replace(/^\s*|\s*$/g, "");
                    if (Text.length < 1)
                        SendError('#Tutor_Name', '#Tutor_Name_validationMessage', 'El campo nombre es mandatorio.');
                    else
                        RemoveError('#Tutor_Name', '#Tutor_Name_validationMessage');
                });

                function SendError(fieldName, fieldValidationName, Message) {
                    $(fieldName).removeClass('input-validation-valid');
                    $(fieldName).addClass('input-validation-error');
                    $(fieldValidationName).removeClass('field-validation-valid');
                    $(fieldValidationName).addClass('field-validation-error');
                    $(fieldValidationName).html(Message);
                    $(fieldValidationName).show();
                }

                function RemoveError(fieldName, fieldValidationName) {
                    $(fieldName).removeClass('input-validation-error');
                    $(fieldName).addClass('input-validation-valid');
                    $(fieldValidationName).removeClass('field-validation-error');
                    $(fieldValidationName).addClass('field-validation-valid');
                    $(fieldValidationName).html('');
                    $(fieldValidationName).hide();
                }

            });

            $('#tutorForm').submit(function (event) {
                event.preventDefault();
                var tutorPatient = {
                    tutor_name: $('#tutorName').val(),
                    tutor_lastName: $('#tutorLastname').val(),
                    tutor_telephone: $('#TutorTelefono').val(),
                    tutor_celphone: $('#TutorCelular').val(),
                    tutor_address: $('#tutorAddress').val(),
                    tutor_identification: $('#TutorCedula').val(),
                    tutor_passport: $('#tutorPassport').val(),


                    patient_name: $('#PatientName').val(),
                    patient_lastName: $('#patientLastName').val(),
                    patient_telephone: $('#Telephone').val(),
                    patient_celphone: $('#Celphone').val(),
                    patient_address: $('#PatientAddress').val(),
                    patient_dateOfbirth: $('#DateofBirth').val(),
                    patient_identification: $('#IdentificationNumber').val(),
                    patient_gender: $('#PatientGender').val(),
                    patient_passport: $('#PatientPassport').val(),
                    patient_insurange: $('#PatientInsurance').val(),
                    patient_active: $('#PatientActivo').val()
                };
                $.post($('#tutorForm').attr('action'), tutorPatient, function () {
                    $('#patientForm').slideUp('slow');
                    $('#tutorForm').slideUp('slow');
                    $('<div id= "successMessage"><p>El paciente y el tutor a sido agregado satisfactoriamente</p></div>');
                    $('#successMessage').addClass('successMessage');
                    $('TutorContainer').append('#successMessage');
                    $('#successMessage').hide();
                    $('#successMessage').show('slow');
                });
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div class="header">
        <h3>
            Registrar paciente</h3>
    </div>
    <div class="main">
        <% using (Html.BeginForm("AddPatient", "Patient", FormMethod.Post, new { @id = "patientForm" }))
           {%>
        <%: Html.ValidationSummary(true)%>
        <fieldset class="main-style">
            <table>
                <tr>
                    <td class="editor-label">
                        Nombre :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.Name, new { @id = "PatientName"})%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Name)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Apellido :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.LastName, new { @id = "patientLastName"  })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.LastName)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Tel&eacute;fono :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.Telephone, new { @Id = "Telephone" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Telephone)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Celular :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.Celphone, new { @Id = "Celphone" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Celphone)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Direcci&oacute;n :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.Address, new { @id = "PatientAddress" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Address)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Fecha de Nacimiento :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.DateofBirth, new { @Id = "DateofBirth" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.DateofBirth)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Identificaci&oacute;n :
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.IdentificationNumber, new { @Id = "IdentificationNumber" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.IdentificationNumber)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Sexo :
                    </td>
                    <td class="editor-field">
                        <%: Html.DropDownListFor(model => model.Patient.Gender, new[] { 
                                new SelectListItem 
                                { 
                                    Text ="Masculino", Value = bool.TrueString
                                }, 
                                new SelectListItem 
                                { 
                                    Text ="Femenino", Value = bool.FalseString
                                } 
                                  }, "Seleccione una opción", new { @id = "PatientGender" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Gender)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Pasaporte
                    </td>
                    <td class="editor-field">
                        <%: Html.TextBoxFor(model => model.Patient.Passport, new { @id = "PatientPassport" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Passport)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Seguro
                    </td>
                    <td class="editor-field">
                        <%: Html.DropDownListFor(model => model.Patient.IdInsurance, Model.InsuranceList, new { @id = "PatientInsurance" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.IdInsurance)%>
                    </td>
                </tr>
                <tr>
                    <td class="editor-label">
                        Activo
                    </td>
                    <td class="editor-field">
                        <%: Html.CheckBoxFor(model => model.Patient.Active, new { @id = "PatientActivo" })%>
                        <%: Html.ValidationMessageFor(model => model.Patient.Active)%>
                    </td>
                </tr>
            </table>
        </fieldset>
    </div>
    <div id="pageFoot" class="footer">
        <h4>
            Acciones
        </h4>
        <fieldset class="main-style2">
            <p>
                <input id="btnSubmit" name="btnSubmit" type="submit" value="Agregar Paciente" />
                <input id="timepicker" name="timepickerName" type="text" />
            </p>
            <p>
                <%:Html.ActionLink("Agregar formulario de emergencias", "GetFormularioEmergencia")%>
                |
                <%: Html.ActionLink("Regresar a la página principal", "SearchPatient")%>
            </p>
        </fieldset>
    </div>
    <% } %>
    <div id="TutorContainer">
        <%Html.RenderAction("create", "Tutor"); %>
    </div>
</asp:Content>
